﻿using System.Collections.Generic;
using ShevaEngine.Core.Modules.Models.Pipeline;

namespace ShevaEngine.Core.Modules.Models
{
    /// <summary>
    /// Model manager.
    /// </summary>
    public class ModelManager
    {
        /// <summary>Singleton.</summary>
        public static readonly ModelManager Instance = new ModelManager();

        /// <summary>Models.</summary>
        public SortedDictionary<string, ShevaModel> Models;

        /// <summary>
        /// Gets sheva model.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public ShevaModel this[string key]
        {
            get
            {
                if (!this.Models.ContainsKey(key))
                {
                    ShevaModel tempModel = new ShevaModel(ShevaEngine.Instance.Content.Load<ModelInternal>(@"Models\" + key));
                    
                    if (!tempModel.IsBoneAnimated)
                        this.Models.Add(key, tempModel);

                    return tempModel;
                }                

                return this.Models[key];
            }
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        public ModelManager()
        {
            this.Models = new SortedDictionary<string, ShevaModel>();
        }
    }
}
